// SHLoadAssignCommand.cpp: implementation of the SHLoadAssignCommand class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "SHLoadAssignCommand.h"
#include "SHLoadAssignStratigy.h"
#include "SHLoadAssignInfo.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

SHLoadAssignCommand::SHLoadAssignStratigyRegisterGenerator SHLoadAssignCommand::m_Generator;

SHLoadAssignCommand::SHLoadAssignCommand(SupportHanger* pSH)
{
	m_pSH = pSH;
}

SHLoadAssignCommand::~SHLoadAssignCommand()
{

}

BOOL SHLoadAssignCommand::Execute()
{
	SHLoadAssignStratigyRegister::Iterator* pIterator = GetSHLoadAssignStratigyRegister().NewIterator();
	if(pIterator == NULL)
		return FALSE;

	for(pIterator->Begin();!pIterator->End();pIterator->Next())
	{
		SHLoadAssignInfo* pInfo = pIterator->Get();
		ASSERT(pInfo);

		SHLoadAssignStratigy* pStratigy = pInfo->CreateObject();
		ASSERT(pStratigy);
		pStratigy->AttachToSH(m_pSH);
		if(pStratigy->Execute())
		{
			delete pIterator;
			return TRUE;
		}
	}
	delete pIterator;

	return FALSE;
}

SHLoadAssignCommand::SHLoadAssignStratigyRegister& SHLoadAssignCommand::GetSHLoadAssignStratigyRegister()
{
	return *m_Generator.Generate();
}